package cn.xhjava.crm.settings.service.impl;

import cn.xhjava.crm.commons.util.ExceptionUtil;
import cn.xhjava.crm.settings.domain.DicValue;
import cn.xhjava.crm.settings.mapper.DicValueMapper;
import cn.xhjava.crm.settings.service.DicValueService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service("dicValueService")
public class DicValueServiceImpl implements DicValueService {
    private static final Logger log = LoggerFactory.getLogger(DicValueServiceImpl.class);

    @Autowired
    private DicValueMapper dicValueMapper;

    @Override
    public List<DicValue> queryDicValueByTypeCode(String typeCode) throws Exception {
        return dicValueMapper.selectDicValueByTypeCode(typeCode);
    }

    @Override
    public List<DicValue> selectForPage(Map<String, Object> map) throws Exception {
        return dicValueMapper.selectForPage(map);
    }

    @Override
    public int selectCountForPage(Map<String, Object> map) throws Exception {
        return dicValueMapper.selectCountForPage(map);
    }

    @Override
    public int delete(String[] ids) throws Exception {
        int res = 1;
        try {
            for (String id : ids) {
                dicValueMapper.deleteByPrimaryKey(id);
            }
        } catch (Exception e) {
            log.error(ExceptionUtil.getStackTrace(e));
            res = 0;
        }
        return res;
    }

    @Override
    public int add(DicValue dicValue) throws Exception {
        return dicValueMapper.insert(dicValue);
    }

    @Override
    public DicValue selectDetailById(String id) throws Exception {
        return dicValueMapper.selectByPrimaryKey(id);
    }

    @Override
    public int update(DicValue dicValue) throws Exception {
        return dicValueMapper.updateByPrimaryKey(dicValue);
    }


}
